package com.bayihouse.model.vo;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.bayihouse.model.entity.Occupant;
import com.bayihouse.utils.MyDateUtils;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.beans.BeanUtils;

import java.io.Serializable;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * 性别sex
 * 生日birthday
 * 是否结婚isMarriage
 * 录入人员 administerName
 * 协管人员 regulatorName
 */
@AllArgsConstructor
@NoArgsConstructor
@Data
public class OccupantVO implements Serializable {
    private static final long serialVersionUID = 1608269712629887842L;

    private Long id;

    /**
     * 入住人员姓名
     */
    private String name;

    /**
     * 身份证号
     */
    private String identity;

    /**
     * 0代表女的,1代表男的
     */
    private String sex;


    /**
     * 民族
     */
    private String ethnicity;

    /**
     * 证件类型
     */
    private String idType;

    /**
     * 生日
     */
    private Integer age;

    /**
     * 电话
     */
    private String telephone;

    /**
     * 是否结婚
     */
    private String isMarriage;

    /**
     * 文化程度
     */
    private String education;

    /**
     * 政治面貌
     */
    private String polOutlook;

    /**
     * 曾用名
     */
    private String nickname;

    /**
     * 身高
     */
    private Double height;

    /**
     * 体型
     */
    private String somatotype;

    /**
     * 脸型
     */
    private String face;

    /**
     * 血型
     */
    private String bloodType;

    /**
     * 婚证编号
     */
    private String MCNumber;

    /**
     * 标签,比如说,敏感人员,常驻人口,租户标签
     */
    private List<String> label;

    /**
     * 这个人住哪里,哪个房间
     */
    private Long roomId;

    /**
     * 户主本人就写户主,其他关系就写与户主的关系,父亲,儿子,女儿,租客就写租客
     */
    private String role;

    /**
     * 户籍-详细地址
     */
    private String address;

    /**
     * 用户添加的时间
     */
    private String createTime;

    /**
     * 用户信息更新的时间
     */
    private String updateTime;


    /**
     * 户籍所在省份
     */
    private String province;

    /**
     * 户籍所在城市
     */
    private String city;

    /**
     * 户籍所在县,区
     */
    private String street;

    private String mannageStreet;

    /**
     * 可以写居住时间,从几月几号居住,什么时候走
     */
    private String detail;


    /**
     * 节育措施
     */
    private String jieyumeasure;

    /**
     * 协管人员
     */
    private Long administerId;

    /**
     * 现居住地
     */
    private String nowAddress;

    /**
     * 录入人员
     */
    private String addUserName;

    /**
     * 来本地事由
     */
    private String PReason;

    /**
     * 职业
     */
    private String work;

    /**
     * 孩子数量
     */
    private Integer childNum;

    /**
     * 婚育证编号
     */
    private String supportNumber;

    /**
     * 房子产权证号
     */
    private String certificateNumber;


    /**
     * 户口类型
     */
    private String accountType;

    private Long addUserId;

    /**
     * 居住证有效期
     */
    private String stayTime;

    /**
     * 从业处所
     */
    private String workplace;

    /**
     * 所属区县
     */
    private String district;

    /**
     * 0表示流入，1表示流出
     */
    private String status;

    private String leavetime;


    public static OccupantVO objToVO(Occupant occupant) throws ParseException {
        OccupantVO occupantVO = new OccupantVO();
        BeanUtils.copyProperties(occupant, occupantVO);
        Gson gson = new Gson();
        occupantVO.setCreateTime(MyDateUtils.dateToString(occupant.getCreateTime()));
        occupantVO.setAge(MyDateUtils.getAge(occupant.getBirthday()));
        occupantVO.setStayTime(occupant.getStayTime() == null ? "未登记" : MyDateUtils.dateToString(occupant.getStayTime()));
        occupantVO.setLabel(gson.fromJson(occupant.getLabel(), new TypeToken<List<String>>() {
        }.getType()));
        if (occupant.getIsMarriage() == null) {
            occupantVO.setIsMarriage("未婚");
        } else {
            occupantVO.setIsMarriage(occupant.getIsMarriage() == 1 ? "已婚" : "未婚");
        }
        occupantVO.setSex(occupant.getSex() == 1 ? "男" : "女");
        if (occupant.getStatus() != null) {
            occupantVO.setStatus(occupant.getStatus() == 0 ? "流入" : "流出");
        }
        if (occupant.getLeavetime() != null) {
            occupantVO.setLeavetime(MyDateUtils.dateToString(occupant.getLeavetime()));
        }
        return occupantVO;
    }


    public static Occupant voToObj(OccupantVO occupantVO) {
        Occupant occupant = new Occupant();
        BeanUtils.copyProperties(occupantVO, occupant);
        return occupant;
    }


}
